home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Hardware / Mac OS USB DDK v1.3f3 / USB.h < prev   
Encoding:
C/C++ Source or Header  |  1999-08-20  |  36.7 KB  |  1,322 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        USB.h
  3.  
  4.      Contains:    Public API for USB Services Library (and associated components)
  5.  
  6.      Version:    
  7.  
  8.      DRI:        David Ferguson
  9.  
  10.      Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  11.  
  12.      Warning:    *** APPLE INTERNAL USE ONLY ***
  13.                  This file may contain unreleased API's
  14.  
  15.      BuildInfo:    Built by:            BuildGod
  16.                  On:                    08/20/99 02:04 PM
  17.                  With Interfacer:    3.0d15   (MPW PowerPC)
  18.                  From:                USB.i
  19.                      Revision:        107
  20.                      Dated:            8/16/99
  21.                      Last change by:    TC
  22.                      Last comment:    Add USBAddDriverForFSSpec.
  23.  
  24.      Bugs:        Report bugs to Radar component "System Interfaces", "Latest"
  25.                  List the version information (from above) in the Problem Description.
  26.  
  27. */
  28. #ifndef __USB__
  29. #define __USB__
  30.  
  31. #ifndef __MACTYPES__
  32. #include <MacTypes.h>
  33. #endif
  34.  
  35. #ifndef __NAMEREGISTRY__
  36. #include <NameRegistry.h>
  37. #endif
  38.  
  39. #ifndef __CODEFRAGMENTS__
  40. #include <CodeFragments.h>
  41. #endif
  42.  
  43. #ifndef __DEVICES__
  44. #include <Devices.h>
  45. #endif
  46.  
  47.  
  48.  
  49.  
  50. #if PRAGMA_ONCE
  51. #pragma once
  52. #endif
  53.  
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57.  
  58. #if PRAGMA_IMPORT
  59. #pragma import on
  60. #endif
  61.  
  62. #if PRAGMA_STRUCT_ALIGN
  63.     #pragma options align=mac68k
  64. #elif PRAGMA_STRUCT_PACKPUSH
  65.     #pragma pack(push, 2)
  66. #elif PRAGMA_STRUCT_PACK
  67.     #pragma pack(2)
  68. #endif
  69.  
  70. /* ************* Constants ************* */
  71. enum {
  72.     kUSBNoErr                    = 0,
  73.     kUSBNoTran                    = 0,
  74.     kUSBNoDelay                    = 0,
  75.     kUSBPending                    = 1,                            /* */
  76.                                                                 /* USB assigned error numbers in range -6900 .. -6999 */
  77.     kUSBBaseError                = -7000,                        /* */
  78.                                                                 /* USB Services Errors */
  79.     kUSBInternalErr                = -6999,                        /* Internal error */
  80.     kUSBUnknownDeviceErr        = -6998,                        /*  device ref not recognised */
  81.     kUSBUnknownPipeErr            = -6997,                        /*  Pipe ref not recognised */
  82.     kUSBTooManyPipesErr            = -6996,                        /*  Too many pipes */
  83.     kUSBIncorrectTypeErr        = -6995,                        /*  Incorrect type */
  84.     kUSBRqErr                    = -6994,                        /*  Request error */
  85.     kUSBUnknownRequestErr        = -6993,                        /*  Unknown request */
  86.     kUSBTooManyTransactionsErr    = -6992,                        /*  Too many transactions */
  87.     kUSBAlreadyOpenErr            = -6991,                        /*  Already open */
  88.     kUSBNoDeviceErr                = -6990,                        /*  No device*/
  89.     kUSBDeviceErr                = -6989,                        /*  Device error */
  90.     kUSBOutOfMemoryErr            = -6988,                        /*  Out of memory */
  91.     kUSBNotFound                = -6987,                        /*  Not found */
  92.     kUSBPBVersionError            = -6986,                        /*  Wrong pbVersion */
  93.     kUSBPBLengthError            = -6985,                        /*  pbLength too small */
  94.     kUSBCompletionError            = -6984,                        /*  no completion routine specified */
  95.     kUSBFlagsError                = -6983,                        /*  Unused flags not zeroed */
  96.     kUSBAbortedError            = -6982,                        /*  Pipe aborted */
  97.     kUSBNoBandwidthError        = -6981,                        /*  Not enough bandwidth available */
  98.     kUSBPipeIdleError            = -6980,                        /*  Pipe is Idle, it will not accept transactions */
  99.     kUSBPipeStalledError        = -6979,                        /*  Pipe has stalled, error needs to be cleared */
  100.     kUSBUnknownInterfaceErr        = -6978,                        /*  Interface ref not recognised */
  101.     kUSBDeviceBusy                = -6977,                        /*  Device is already being configured */
  102.     kUSBDevicePowerProblem        = -6976,                        /*  Device has a power problem */
  103.     kUSBInvalidBuffer            = -6975,                        /* bad buffer, usually nil */
  104.     kUSBDeviceSuspended            = -6974,                        /* Device is suspended */
  105.     kUSBDeviceNotSuspended        = -6973,                        /* device is not suspended for resume */
  106.     kUSBDeviceDisconnected        = -6972,                        /* Disconnected during suspend or reset */
  107.     kUSBTimedOut                = -6971,                        /* Transaction timed out. */
  108.                                                                 /* USB internal errors are in range -6960 to -6951*/
  109.                                                                 /* please do not use this range*/
  110.                                                                 /* */
  111.     kUSBInternalReserved1        = -6960,                        /* reserved*/
  112.     kUSBInternalReserved2        = -6959,
  113.     kUSBInternalReserved3        = -6958,
  114.     kUSBInternalReserved4        = -6957,
  115.     kUSBInternalReserved5        = -6956,
  116.     kUSBInternalReserved6        = -6955,
  117.     kUSBInternalReserved7        = -6954,
  118.     kUSBInternalReserved8        = -6953,
  119.     kUSBInternalReserved9        = -6952,
  120.     kUSBInternalReserved10        = -6951,                        /* */
  121.                                                                 /* USB Manager Errors */
  122.     kUSBBadDispatchTable        = -6950,                        /* Improper driver dispatch table     */
  123.     kUSBUnknownNotification        = -6949,                        /* Notification type not defined     */
  124.     kUSBNotHandled                = -6987,                        /* Notification was not handled    (same as NotFound)*/
  125.     kUSBQueueFull                = -6948,                        /* Internal queue maxxed     */
  126.                                                                 /* */
  127.                                                                 /* Hardware Errors */
  128.                                                                 /* Note pipe stalls are communication */
  129.                                                                 /* errors. The affected pipe can not */
  130.                                                                 /* be used until USBClearPipeStallByReference  */
  131.                                                                 /* is used */
  132.                                                                 /* kUSBEndpointStallErr is returned in */
  133.                                                                 /* response to a stall handshake */
  134.                                                                 /* from a device. The device has to be */
  135.                                                                 /* cleared before a USBClearPipeStallByReference */
  136.                                                                 /* can be used */
  137.     kUSBLinkErr                    = -6916,
  138.     kUSBCRCErr                    = -6915,                        /*  Pipe stall, bad CRC */
  139.     kUSBBitstufErr                = -6914,                        /*  Pipe stall, bitstuffing */
  140.     kUSBDataToggleErr            = -6913,                        /*  Pipe stall, Bad data toggle */
  141.     kUSBEndpointStallErr        = -6912,                        /*  Device didn't understand */
  142.     kUSBNotRespondingErr        = -6911,                        /*  Pipe stall, No device, device hung */
  143.     kUSBPIDCheckErr                = -6910,                        /*  Pipe stall, PID CRC error */
  144.     kUSBWrongPIDErr                = -6909,                        /*  Pipe stall, Bad or wrong PID */
  145.     kUSBOverRunErr                = -6908,                        /*  Packet too large or more data than buffer */
  146.     kUSBUnderRunErr                = -6907,                        /*  Less data than buffer */
  147.     kUSBRes1Err                    = -6906,
  148.     kUSBRes2Err                    = -6905,
  149.     kUSBBufOvrRunErr            = -6904,                        /*  Host hardware failure on data in, PCI busy? */
  150.     kUSBBufUnderRunErr            = -6903,                        /*  Host hardware failure on data out, PCI busy? */
  151.     kUSBNotSent1Err                = -6902,                        /*  Transaction not sent */
  152.     kUSBNotSent2Err                = -6901                            /*  Transaction not sent */
  153. };
  154.  
  155. enum {
  156.                                                                 /* Flags */
  157.     kUSBTaskTimeFlag            = 1,
  158.     kUSBHubPower                = 2,
  159.     kUSBPowerReset                = 4,
  160.     kUSBHubReaddress            = 8,
  161.     kUSBAddressRequest            = 16,
  162.     kUSBReturnOnException        = 32,
  163.     kUSBNo5SecTimeout            = 64,
  164.     kUSBTimeout                    = 128,
  165.     kUSBNoDataTimeout            = 256
  166. };
  167.  
  168. enum {
  169.                                                                 /* Hub messages */
  170.     kUSBHubPortResetRequest        = 1,
  171.     kUSBHubPortSuspendRequest    = 2
  172. };
  173.  
  174. enum {
  175.     kVendorID_AppleComputer        = 0x05AC
  176. };
  177.  
  178. /* ************* types ************* */
  179.  
  180. typedef SInt32                             USBReference;
  181. typedef USBReference                     USBDeviceRef;
  182. typedef USBDeviceRef *                    USBDeviceRefPtr;
  183. typedef USBReference                     USBInterfaceRef;
  184. typedef USBReference                     USBPipeRef;
  185. typedef USBReference                     USBBusRef;
  186. typedef UInt32                             USBPipeState;
  187. typedef UInt32                             USBCount;
  188. typedef UInt32                             USBFlags;
  189. typedef UInt8                             USBRequest;
  190. typedef UInt8                             USBDirection;
  191. typedef UInt8                             USBRqRecipient;
  192. typedef UInt8                             USBRqType;
  193. typedef UInt16                             USBRqIndex;
  194. typedef UInt16                             USBRqValue;
  195.  
  196.  
  197.  
  198. struct usbControlBits {
  199.     UInt8                             BMRequestType;
  200.     UInt8                             BRequest;
  201.     USBRqValue                         WValue;
  202.     USBRqIndex                         WIndex;
  203.     UInt16                             reserved4;
  204. };
  205. typedef struct usbControlBits            usbControlBits;
  206.  
  207. struct USBIsocFrame {
  208.     OSStatus                         frStatus;
  209.     UInt16                             frReqCount;
  210.     UInt16                             frActCount;
  211. };
  212. typedef struct USBIsocFrame                USBIsocFrame;
  213. enum {
  214.     kUSBMaxIsocFrameReqCount    = 1023                            /* maximum size (bytes) of any one Isoc frame*/
  215. };
  216.  
  217.  
  218. struct usbIsocBits {
  219.     USBIsocFrame *                    FrameList;
  220.     UInt32                             NumFrames;
  221. };
  222. typedef struct usbIsocBits                usbIsocBits;
  223.  
  224. struct usbHubBits {
  225.     UInt32                             Request;
  226.     UInt32                             Spare;
  227. };
  228. typedef struct usbHubBits                usbHubBits;
  229. typedef struct USBPB                     USBPB;
  230. typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
  231.  
  232. union USBVariantBits {
  233.     usbControlBits                     cntl;
  234.     usbIsocBits                     isoc;
  235.     usbHubBits                         hub;
  236. };
  237. typedef union USBVariantBits            USBVariantBits;
  238.  
  239. struct USBPB {
  240.  
  241.     void *                            qlink;
  242.     UInt16                             qType;
  243.     UInt16                             pbLength;
  244.     UInt16                             pbVersion;
  245.     UInt16                             reserved1;
  246.     UInt32                             reserved2;
  247.  
  248.     OSStatus                         usbStatus;
  249.     USBCompletion                     usbCompletion;
  250.     UInt32                             usbRefcon;
  251.  
  252.     USBReference                     usbReference;
  253.  
  254.     void *                            usbBuffer;
  255.     USBCount                         usbReqCount;
  256.     USBCount                         usbActCount;
  257.  
  258.     USBFlags                         usbFlags;
  259.  
  260.     USBVariantBits                     usb;
  261.  
  262.     UInt32                             usbFrame;
  263.  
  264.     UInt8                             usbClassType;
  265.     UInt8                             usbSubclass;
  266.     UInt8                             usbProtocol;
  267.     UInt8                             usbOther;
  268.  
  269.     UInt32                             reserved6;
  270.     UInt16                             reserved7;
  271.     UInt16                             reserved8;
  272.  
  273. };
  274.  
  275.  
  276. typedef USBPB *                            USBPBPtr;
  277. #if !defined(OLDUSBNAMES)
  278. #define OLDUSBNAMES 0
  279. #endif
  280.  
  281. #if OLDUSBNAMES
  282. #define usbBMRequestType  usb.cntl.BMRequestType
  283. #define usbBRequest       usb.cntl.BRequest
  284. #define usbWValue         usb.cntl.WValue
  285. #define usbWIndex         usb.cntl.WIndex
  286. #endif
  287.  
  288. struct uslReq {
  289.     USBDirection                     usbDirection;
  290.     USBRqType                         usbType;
  291.     USBRqRecipient                     usbRecipient;
  292.     USBRequest                         usbRequest;
  293. };
  294. typedef struct uslReq                    uslReq;
  295.  
  296. enum {
  297.                                                                 /* BT 19Aug98, bump up to v1.10 for Isoc*/
  298.     kUSBCurrentPBVersion        = 0x0100,                        /* v1.00*/
  299.     kUSBIsocPBVersion            = 0x0109,                        /* v1.10*/
  300.     kUSBCurrentHubPB            = kUSBIsocPBVersion
  301. };
  302.  
  303.  
  304.  
  305.  
  306. #define kUSBNoCallBack ((USBCompletion)-1L)
  307.  
  308.  
  309. typedef UInt8                             bcdUSB;
  310. enum {
  311.     kUSBControl                    = 0,
  312.     kUSBIsoc                    = 1,
  313.     kUSBBulk                    = 2,
  314.     kUSBInterrupt                = 3,
  315.     kUSBAnyType                    = 0xFF
  316. };
  317.  
  318. /* endpoint type */
  319. enum {
  320.     kUSBOut                        = 0,
  321.     kUSBIn                        = 1,
  322.     kUSBNone                    = 2,
  323.     kUSBAnyDirn                    = 3
  324. };
  325.  
  326. /*USBDirection*/
  327. enum {
  328.     kUSBStandard                = 0,
  329.     kUSBClass                    = 1,
  330.     kUSBVendor                    = 2
  331. };
  332.  
  333. /*USBRqType*/
  334. enum {
  335.     kUSBDevice                    = 0,
  336.     kUSBInterface                = 1,
  337.     kUSBEndpoint                = 2,
  338.     kUSBOther                    = 3
  339. };
  340.  
  341. /*USBRqRecipient*/
  342. enum {
  343.     kUSBRqGetStatus                = 0,
  344.     kUSBRqClearFeature            = 1,
  345.     kUSBRqReserved1                = 2,
  346.     kUSBRqSetFeature            = 3,
  347.     kUSBRqReserved2                = 4,
  348.     kUSBRqSetAddress            = 5,
  349.     kUSBRqGetDescriptor            = 6,
  350.     kUSBRqSetDescriptor            = 7,
  351.     kUSBRqGetConfig                = 8,
  352.     kUSBRqSetConfig                = 9,
  353.     kUSBRqGetInterface            = 10,
  354.     kUSBRqSetInterface            = 11,
  355.     kUSBRqSyncFrame                = 12
  356. };
  357.  
  358. /*USBRequest*/
  359.  
  360. enum {
  361.     kUSBDeviceDesc                = 1,
  362.     kUSBConfDesc                = 2,
  363.     kUSBStringDesc                = 3,
  364.     kUSBInterfaceDesc            = 4,
  365.     kUSBEndpointDesc            = 5,
  366.     kUSBHIDDesc                    = 0x21,
  367.     kUSBReportDesc                = 0x22,
  368.     kUSBPhysicalDesc            = 0x23,
  369.     kUSBHUBDesc                    = 0x29
  370. };
  371.  
  372. /* descriptorType */
  373.  
  374. enum {
  375.     kUSBFeatureDeviceRemoteWakeup = 1,
  376.     kUSBFeatureEndpointStall    = 0
  377. };
  378.  
  379. /* Feature selectors */
  380. enum {
  381.     kUSBActive                    = 0,                            /* Pipe can accept new transactions*/
  382.     kUSBIdle                    = 1,                            /* Pipe will not accept new transactions*/
  383.     kUSBStalled                    = 2,                            /* An error occured on the pipe*/
  384.     kUSBSuspended                = 4                                /* Device is suspended*/
  385. };
  386.  
  387. enum {
  388.     kUSB100mAAvailable            = 50,
  389.     kUSB500mAAvailable            = 250,
  390.     kUSB100mA                    = 50,
  391.     kUSBAtrBusPowered            = 0x80,
  392.     kUSBAtrSelfPowered            = 0x40,
  393.     kUSBAtrRemoteWakeup            = 0x20
  394. };
  395.  
  396. enum {
  397.     kUSBRel10                    = 0x0100
  398. };
  399.  
  400. #define USB_CONSTANT16(x)    ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
  401. enum {
  402.     kUSBDeviceDescriptorLength    = 0x12,
  403.     kUSBInterfaceDescriptorLength = 0x09
  404. };
  405.  
  406.  
  407. struct USBDeviceDescriptor {
  408.     UInt8                             length;
  409.     UInt8                             descType;
  410.     UInt16                             usbRel;
  411.     UInt8                             deviceClass;
  412.     UInt8                             deviceSubClass;
  413.     UInt8                             protocol;
  414.     UInt8                             maxPacketSize;
  415.     UInt16                             vendor;
  416.     UInt16                             product;
  417.     UInt16                             devRel;
  418.     UInt8                             manuIdx;
  419.     UInt8                             prodIdx;
  420.     UInt8                             serialIdx;
  421.     UInt8                             numConf;
  422. };
  423. typedef struct USBDeviceDescriptor        USBDeviceDescriptor;
  424. #ifndef OLDCLASSNAMES
  425. #ifndef __cplusplus
  426. #define class deviceClass
  427. #define subClass deviceSubClass
  428. #endif
  429. #endif
  430. typedef USBDeviceDescriptor *            USBDeviceDescriptorPtr;
  431.  
  432. struct USBDescriptorHeader {
  433.     UInt8                             length;
  434.     UInt8                             descriptorType;
  435. };
  436. typedef struct USBDescriptorHeader        USBDescriptorHeader;
  437. typedef USBDescriptorHeader *            USBDescriptorHeaderPtr;
  438.  
  439. struct USBConfigurationDescriptor {
  440.     UInt8                             length;
  441.     UInt8                             descriptorType;
  442.     UInt16                             totalLength;
  443.     UInt8                             numInterfaces;
  444.     UInt8                             configValue;
  445.     UInt8                             configStrIndex;
  446.     UInt8                             attributes;
  447.     UInt8                             maxPower;
  448. };
  449. typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
  450. typedef USBConfigurationDescriptor *    USBConfigurationDescriptorPtr;
  451.  
  452. struct USBInterfaceDescriptor {
  453.     UInt8                             length;
  454.     UInt8                             descriptorType;
  455.     UInt8                             interfaceNumber;
  456.     UInt8                             alternateSetting;
  457.     UInt8                             numEndpoints;
  458.     UInt8                             interfaceClass;
  459.     UInt8                             interfaceSubClass;
  460.     UInt8                             interfaceProtocol;
  461.     UInt8                             interfaceStrIndex;
  462. };
  463. typedef struct USBInterfaceDescriptor    USBInterfaceDescriptor;
  464. typedef USBInterfaceDescriptor *        USBInterfaceDescriptorPtr;
  465.  
  466. struct USBEndPointDescriptor {
  467.     UInt8                             length;
  468.     UInt8                             descriptorType;
  469.     UInt8                             endpointAddress;
  470.     UInt8                             attributes;
  471.     UInt16                             maxPacketSize;
  472.     UInt8                             interval;
  473. };
  474. typedef struct USBEndPointDescriptor    USBEndPointDescriptor;
  475. typedef USBEndPointDescriptor *            USBEndPointDescriptorPtr;
  476.  
  477. struct USBHIDDescriptor {
  478.     UInt8                             descLen;
  479.     UInt8                             descType;
  480.     UInt16                             descVersNum;
  481.     UInt8                             hidCountryCode;
  482.     UInt8                             hidNumDescriptors;
  483.     UInt8                             hidDescriptorType;
  484.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  485.     UInt8                             hidDescriptorLengthHi;
  486. };
  487. typedef struct USBHIDDescriptor            USBHIDDescriptor;
  488. typedef USBHIDDescriptor *                USBHIDDescriptorPtr;
  489.  
  490. struct USBHIDReportDesc {
  491.     UInt8                             hidDescriptorType;
  492.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  493.     UInt8                             hidDescriptorLengthHi;
  494. };
  495. typedef struct USBHIDReportDesc            USBHIDReportDesc;
  496. typedef USBHIDReportDesc *                USBHIDReportDescPtr;
  497.  
  498. struct USBHubPortStatus {
  499.     UInt16                             portFlags;                    /* Port status flags */
  500.     UInt16                             portChangeFlags;            /* Port changed flags */
  501. };
  502. typedef struct USBHubPortStatus            USBHubPortStatus;
  503. typedef USBHubPortStatus *                USBHubPortStatusPtr;
  504. /* ********* ProtoTypes *************** */
  505. /* For dealing with endianisms */
  506. EXTERN_API_C( UInt16 )
  507. HostToUSBWord                    (UInt16                 value);
  508.  
  509. EXTERN_API_C( UInt16 )
  510. USBToHostWord                    (UInt16                 value);
  511.  
  512. EXTERN_API_C( UInt32 )
  513. HostToUSBLong                    (UInt32                 value);
  514.  
  515. EXTERN_API_C( UInt32 )
  516. USBToHostLong                    (UInt32                 value);
  517.  
  518. /* Main prototypes */
  519. /* Transfer commands */
  520. EXTERN_API_C( OSStatus )
  521. USBDeviceRequest                (USBPB *                pb);
  522.  
  523. /*extern OSStatus USBOpenPipe(USBPB *pb);*/
  524. EXTERN_API_C( OSStatus )
  525. USBBulkWrite                    (USBPB *                pb);
  526.  
  527. EXTERN_API_C( OSStatus )
  528. USBBulkRead                        (USBPB *                pb);
  529.  
  530. EXTERN_API_C( OSStatus )
  531. USBIntRead                        (USBPB *                pb);
  532.  
  533. EXTERN_API_C( OSStatus )
  534. USBIntWrite                        (USBPB *                pb);
  535.  
  536. EXTERN_API_C( OSStatus )
  537. USBIsocRead                        (USBPB *                pb);
  538.  
  539. EXTERN_API_C( OSStatus )
  540. USBIsocWrite                    (USBPB *                pb);
  541.  
  542. /* Pipe state control */
  543. EXTERN_API_C( OSStatus )
  544. USBClearPipeStallByReference    (USBPipeRef             ref);
  545.  
  546. EXTERN_API_C( OSStatus )
  547. USBAbortPipeByReference            (USBReference             ref);
  548.  
  549. EXTERN_API_C( OSStatus )
  550. USBResetPipeByReference            (USBReference             ref);
  551.  
  552. EXTERN_API_C( OSStatus )
  553. USBSetPipeIdleByReference        (USBPipeRef             ref);
  554.  
  555. EXTERN_API_C( OSStatus )
  556. USBSetPipeActiveByReference        (USBPipeRef             ref);
  557.  
  558. EXTERN_API_C( OSStatus )
  559. USBClosePipeByReference            (USBPipeRef             ref);
  560.  
  561. EXTERN_API_C( OSStatus )
  562. USBGetPipeStatusByReference        (USBReference             ref,
  563.                                  USBPipeState *            state);
  564.  
  565.  
  566. /* Configuration services */
  567. EXTERN_API_C( OSStatus )
  568. USBFindNextInterface            (USBPB *                pb);
  569.  
  570. EXTERN_API_C( OSStatus )
  571. USBOpenDevice                    (USBPB *                pb);
  572.  
  573. EXTERN_API_C( OSStatus )
  574. USBSetConfiguration                (USBPB *                pb);
  575.  
  576. EXTERN_API_C( OSStatus )
  577. USBNewInterfaceRef                (USBPB *                pb);
  578.  
  579. EXTERN_API_C( OSStatus )
  580. USBDisposeInterfaceRef            (USBPB *                pb);
  581.  
  582. EXTERN_API_C( OSStatus )
  583. USBConfigureInterface            (USBPB *                pb);
  584.  
  585. EXTERN_API_C( OSStatus )
  586. USBFindNextPipe                    (USBPB *                pb);
  587.  
  588.  
  589. /* Dealing with descriptors. */
  590. /* Note most of this is temprorary */
  591. EXTERN_API_C( OSStatus )
  592. USBGetConfigurationDescriptor    (USBPB *                pb);
  593.  
  594. EXTERN_API_C( OSStatus )
  595. USBGetFullConfigurationDescriptor (USBPB *                pb);
  596.  
  597. EXTERN_API_C( OSStatus )
  598. USBFindNextEndpointDescriptorImmediate (USBPB *            pb);
  599.  
  600. EXTERN_API_C( OSStatus )
  601. USBFindNextInterfaceDescriptorImmediate (USBPB *        pb);
  602.  
  603. EXTERN_API_C( OSStatus )
  604. USBFindNextAssociatedDescriptor    (USBPB *                pb);
  605.  
  606.  
  607.  
  608. /* Utility functions */
  609. EXTERN_API_C( OSStatus )
  610. USBResetDevice                    (USBPB *                pb);
  611.  
  612. EXTERN_API_C( OSStatus )
  613. USBSuspendDevice                (USBPB *                pb);
  614.  
  615. EXTERN_API_C( OSStatus )
  616. USBResumeDeviceByReference        (USBReference             refIn);
  617.  
  618. EXTERN_API_C( OSStatus )
  619. USBGetFrameNumberImmediate        (USBPB *                pb);
  620.  
  621. EXTERN_API_C( OSStatus )
  622. USBDelay                        (USBPB *                pb);
  623.  
  624. EXTERN_API_C( OSStatus )
  625. USBSAbortQueuesByReference        (USBReference             ref);
  626.  
  627. EXTERN_API_C( OSStatus )
  628. USBAllocMem                        (USBPB *                pb);
  629.  
  630. EXTERN_API_C( OSStatus )
  631. USBDeallocMem                    (USBPB *                pb);
  632.  
  633. /* Expert interface functions */
  634. EXTERN_API_C( OSStatus )
  635. USBExpertInstallInterfaceDriver    (USBDeviceRef             ref,
  636.                                  USBDeviceDescriptorPtr  desc,
  637.                                  USBInterfaceDescriptorPtr  interfacePtr,
  638.                                  USBReference             hubRef,
  639.                                  UInt32                 busPowerAvailable);
  640.  
  641. EXTERN_API_C( OSStatus )
  642. USBExpertRemoveInterfaceDriver    (USBDeviceRef             ref);
  643.  
  644. EXTERN_API_C( OSStatus )
  645. USBExpertInstallDeviceDriver    (USBDeviceRef             ref,
  646.                                  USBDeviceDescriptorPtr  desc,
  647.                                  USBReference             hubRef,
  648.                                  UInt32                 port,
  649.                                  UInt32                 busPowerAvailable);
  650.  
  651. EXTERN_API_C( OSStatus )
  652. USBExpertRemoveDeviceDriver        (USBDeviceRef             ref);
  653.  
  654. EXTERN_API_C( OSStatus )
  655. USBExpertStatus                    (USBDeviceRef             ref,
  656.                                  void *                    pointer,
  657.                                  UInt32                 value);
  658.  
  659. EXTERN_API_C( OSStatus )
  660. USBExpertFatalError                (USBDeviceRef             ref,
  661.                                  OSStatus                 status,
  662.                                  void *                    pointer,
  663.                                  UInt32                 value);
  664.  
  665. EXTERN_API_C( OSStatus )
  666. USBExpertNotify                    (void *                    note);
  667.  
  668. EXTERN_API_C( OSStatus )
  669. USBExpertStatusLevel            (UInt32                 level,
  670.                                  USBDeviceRef             ref,
  671.                                  StringPtr                 status,
  672.                                  UInt32                 value);
  673.  
  674. EXTERN_API_C( UInt32 )
  675. USBExpertGetStatusLevel            (void);
  676.  
  677. EXTERN_API_C( void )
  678. USBExpertSetStatusLevel            (UInt32                 level);
  679.  
  680.  
  681.  
  682. EXTERN_API_C( OSStatus )
  683. USBExpertSetDevicePowerStatus    (USBDeviceRef             ref,
  684.                                  UInt32                 reserved1,
  685.                                  UInt32                 reserved2,
  686.                                  UInt32                 powerStatus,
  687.                                  UInt32                 busPowerAvailable,
  688.                                  UInt32                 busPowerNeeded);
  689.  
  690. enum {
  691.     kUSBDevicePower_PowerOK        = 0,
  692.     kUSBDevicePower_BusPowerInsufficient = 1,
  693.     kUSBDevicePower_BusPowerNotAllFeatures = 2,
  694.     kUSBDevicePower_SelfPowerInsufficient = 3,
  695.     kUSBDevicePower_SelfPowerNotAllFeatures = 4,
  696.     kUSBDevicePower_HubPortOk    = 5,
  697.     kUSBDevicePower_HubPortOverCurrent = 6,
  698.     kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
  699.     kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
  700.     kUSBDevicePower_Reserved3    = 9,
  701.     kUSBDevicePower_Reserved4    = 10
  702. };
  703.  
  704.  
  705. /* For hubs only */
  706. EXTERN_API_C( OSStatus )
  707. USBHubAddDevice                    (USBPB *                pb);
  708.  
  709. EXTERN_API_C( OSStatus )
  710. USBHubConfigurePipeZero            (USBPB *                pb);
  711.  
  712. EXTERN_API_C( OSStatus )
  713. USBHubSetAddress                (USBPB *                pb);
  714.  
  715. EXTERN_API_C( OSStatus )
  716. USBHubDeviceRemoved                (USBPB *                pb);
  717.  
  718.  
  719. EXTERN_API_C( UInt8 )
  720. USBMakeBMRequestType            (UInt8                     direction,
  721.                                  UInt8                     reqtype,
  722.                                  UInt8                     recipient);
  723.  
  724. EXTERN_API_C( OSStatus )
  725. USBControlRequest                (USBPB *                pb);
  726.  
  727.  
  728. typedef UInt32                             USBLocationID;
  729. enum {
  730.     kUSBLocationNibbleFormat    = 0                                /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
  731. };
  732.  
  733.  
  734. enum {
  735.     kNoDeviceRef                = -1
  736. };
  737.  
  738. /* Status Level constants*/
  739. /*
  740. Level 1: Fatal errors
  741. Level 2: General errors that may or may not effect operation
  742. Level 3: General driver messages.  The "AddStatus" call that drivers use comes through as a level 3.  This is also the default level at boot time.
  743. Level 4: Important status messages from the Expert and USL.
  744. Level 5: General status messages from the Expert and USL.
  745. */
  746. enum {
  747.     kUSBStatusLevelFatal        = 1,
  748.     kUSBStatusLevelError        = 2,
  749.     kUSBStatusLevelClient        = 3,
  750.     kUSBStatusLevelGeneral        = 4,
  751.     kUSBStatusLevelVerbose        = 5
  752. };
  753.  
  754. /* Expert Notification Types*/
  755. typedef UInt8                             USBNotificationType;
  756. typedef UInt8                             USBDriverMessage;
  757. enum {
  758.     kNotifyAddDevice            = 0x00,
  759.     kNotifyRemoveDevice            = 0x01,
  760.     kNotifyAddInterface            = 0x02,
  761.     kNotifyRemoveInterface        = 0x03,
  762.     kNotifyGetDeviceDescriptor    = 0x04,
  763.     kNotifyGetInterfaceDescriptor = 0x05,
  764.     kNotifyGetNextDeviceByClass    = 0x06,
  765.     kNotifyGetDriverConnectionID = 0x07,
  766.     kNotifyInstallDeviceNotification = 0x08,
  767.     kNotifyRemoveDeviceNotification = 0x09,
  768.     kNotifyDeviceRefToBusRef    = 0x0A,
  769.     kNotifyDriverNotify            = 0x0C,
  770.     kNotifyParentNotify            = 0x0D,
  771.     kNotifyAnyEvent                = 0xFF,
  772.     kNotifyPowerState            = 0x17,
  773.     kNotifyStatus                = 0x18,
  774.     kNotifyFatalError            = 0x19,
  775.     kNotifyStatusLevel            = 0x20
  776. };
  777.  
  778. /*
  779.    USB Manager wildcard constants for USBGetNextDeviceByClass
  780.    and USBInstallDeviceNotification.
  781. */
  782. typedef UInt16                             USBManagerWildcard;
  783. enum {
  784.     kUSBAnyClass                = 0xFFFF,
  785.     kUSBAnySubClass                = 0xFFFF,
  786.     kUSBAnyProtocol                = 0xFFFF,
  787.     kUSBAnyVendor                = 0xFFFF,
  788.     kUSBAnyProduct                = 0xFFFF
  789. };
  790.  
  791.  
  792.  
  793.  
  794. struct ExpertNotificationData {
  795.     USBNotificationType             notification;
  796.     UInt8                             filler[1];                    /* unused due to 2-byte 68k alignment*/
  797.     USBDeviceRef *                    deviceRef;
  798.     UInt32                             busPowerAvailable;
  799.     void *                            data;
  800.     UInt32                             info1;
  801.     UInt32                             info2;
  802. };
  803. typedef struct ExpertNotificationData    ExpertNotificationData;
  804. typedef ExpertNotificationData *        ExpertNotificationDataPtr;
  805. /* Definition of function pointer passed in ExpertEntryProc*/
  806. typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
  807. /* Definition of expert's callback installation function*/
  808. typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
  809. /* Device Notification Callback Routine*/
  810. typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
  811. /* Device Notification Parameter Block*/
  812.  
  813. struct USBDeviceNotificationParameterBlock {
  814.     UInt16                             pbLength;
  815.     UInt16                             pbVersion;
  816.     USBNotificationType             usbDeviceNotification;
  817.     UInt8                             reserved1[1];                /* needed because of 2-byte 68k alignment*/
  818.     USBDeviceRef                     usbDeviceRef;
  819.     UInt16                             usbClass;
  820.     UInt16                             usbSubClass;
  821.     UInt16                             usbProtocol;
  822.     UInt16                             usbVendor;
  823.     UInt16                             usbProduct;
  824.     OSStatus                         result;
  825.     UInt32                             token;
  826.     USBDeviceNotificationCallbackProcPtr  callback;
  827.     UInt32                             refcon;
  828. };
  829. typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
  830. typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
  831. /* Definition of USBDriverNotificationCallback Routine*/
  832. typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
  833. /* Public Functions*/
  834. EXTERN_API_C( UInt32 )
  835. USBGetVersion                    (void);
  836.  
  837. EXTERN_API_C( OSStatus )
  838. USBGetNextDeviceByClass            (USBDeviceRef *            deviceRef,
  839.                                  CFragConnectionID *    connID,
  840.                                  UInt16                 theClass,
  841.                                  UInt16                 theSubClass,
  842.                                  UInt16                 theProtocol);
  843.  
  844. EXTERN_API_C( OSStatus )
  845. USBGetDeviceDescriptor            (USBDeviceRef *            deviceRef,
  846.                                  USBDeviceDescriptor *    deviceDescriptor,
  847.                                  UInt32                 size);
  848.  
  849. EXTERN_API_C( OSStatus )
  850. USBGetInterfaceDescriptor        (USBInterfaceRef *        interfaceRef,
  851.                                  USBInterfaceDescriptor * interfaceDescriptor,
  852.                                  UInt32                 size);
  853.  
  854. EXTERN_API_C( OSStatus )
  855. USBGetDriverConnectionID        (USBDeviceRef *            deviceRef,
  856.                                  CFragConnectionID *    connID);
  857.  
  858. EXTERN_API_C( void )
  859. USBInstallDeviceNotification    (USBDeviceNotificationParameterBlock * pb);
  860.  
  861. EXTERN_API_C( OSStatus )
  862. USBRemoveDeviceNotification        (UInt32                 token);
  863.  
  864. EXTERN_API_C( OSStatus )
  865. USBDeviceRefToBusRef            (USBDeviceRef *            deviceRef,
  866.                                  USBBusRef *            busRef);
  867.  
  868. EXTERN_API_C( OSStatus )
  869. USBDriverNotify                    (USBReference             reference,
  870.                                  USBDriverMessage         mesg,
  871.                                  UInt32                 refcon,
  872.                                  USBDriverNotificationCallbackPtr  callback);
  873.  
  874. EXTERN_API_C( OSStatus )
  875. USBExpertNotifyParent            (USBReference             reference,
  876.                                  void *                    pointer);
  877.  
  878. EXTERN_API_C( OSStatus )
  879. USBAddShimFromDisk                (FSSpec *                shimFilePtr);
  880.  
  881. EXTERN_API_C( OSStatus )
  882. USBAddDriverForFSSpec            (USBReference             reference,
  883.                                  FSSpec *                fileSpec);
  884.  
  885. typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
  886. typedef CALLBACK_API_C( void , HIDNotificationProcPtr )(UInt32 refcon, UInt32 reportSize, void *theReport, USBReference theInterfaceRef);
  887. /* HID Install Interrupt prototype*/
  888. typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
  889. /* HID Poll Device prototype*/
  890. typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
  891. /* HID Control Device prototype*/
  892. typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
  893. /* HID Get Device Info prototype*/
  894. typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
  895. /* HID Enter Polled Mode prototype*/
  896. typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
  897. /* HID Exit Polled Mode prototype*/
  898. typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
  899. /* HID Install Notification prototype*/
  900. typedef CALLBACK_API_C( OSStatus , USBHIDInstallNotificationProcPtr )(HIDNotificationProcPtr pNotificationProc, UInt32 refcon);
  901. enum {
  902.     kHIDStandardDispatchVersion    = 0,
  903.     kHIDReservedDispatchVersion    = 1,
  904.     kHIDNotificationDispatchVersion = 2,
  905.     kHIDCurrentDispatchVersion    = 2
  906. };
  907.  
  908.  
  909.  
  910. struct USBHIDRev2DispatchTable {
  911.     UInt32                             hidDispatchVersion;
  912.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  913.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  914.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  915.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  916.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  917.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  918.     USBHIDInstallNotificationProcPtr  pUSBHIDInstallNotification;
  919. };
  920. typedef struct USBHIDRev2DispatchTable    USBHIDRev2DispatchTable;
  921. typedef USBHIDRev2DispatchTable *        USBHIDRev2DispatchTablePtr;
  922.  
  923. struct USBHIDModuleDispatchTable {
  924.     UInt32                             hidDispatchVersion;
  925.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  926.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  927.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  928.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  929.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  930.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  931. };
  932. typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
  933. typedef USBHIDModuleDispatchTable *        USBHIDModuleDispatchTablePtr;
  934. /*    Prototypes Tue, Mar 17, 1998 4:54:30 PM    */
  935. EXTERN_API_C( OSStatus )
  936. USBHIDInstallInterrupt            (HIDInterruptProcPtr     HIDInterruptFunction,
  937.                                  UInt32                 refcon);
  938.  
  939. EXTERN_API_C( OSStatus )
  940. USBHIDPollDevice                (void);
  941.  
  942. EXTERN_API_C( OSStatus )
  943. USBHIDControlDevice                (UInt32                 theControlSelector,
  944.                                  void *                    theControlData);
  945.  
  946. EXTERN_API_C( OSStatus )
  947. USBHIDGetDeviceInfo                (UInt32                 theInfoSelector,
  948.                                  void *                    theInfo);
  949.  
  950. EXTERN_API_C( OSStatus )
  951. USBHIDEnterPolledMode            (void);
  952.  
  953. EXTERN_API_C( OSStatus )
  954. USBHIDExitPolledMode            (void);
  955.  
  956. EXTERN_API_C( OSStatus )
  957. USBHIDInstallNotification        (HIDNotificationProcPtr  HIDNotificationFunction,
  958.                                  UInt32                 refcon);
  959.  
  960. EXTERN_API_C( void )
  961. HIDNotification                    (UInt32                 devicetype,
  962.                                  UInt8                     NewHIDData[],
  963.                                  UInt8                     OldHIDData[]);
  964.  
  965. enum {
  966.     kHIDRqGetReport                = 1,
  967.     kHIDRqGetIdle                = 2,
  968.     kHIDRqGetProtocol            = 3,
  969.     kHIDRqSetReport                = 9,
  970.     kHIDRqSetIdle                = 10,
  971.     kHIDRqSetProtocol            = 11
  972. };
  973.  
  974. enum {
  975.     kHIDRtInputReport            = 1,
  976.     kHIDRtOutputReport            = 2,
  977.     kHIDRtFeatureReport            = 3
  978. };
  979.  
  980. enum {
  981.     kHIDBootProtocolValue        = 0,
  982.     kHIDReportProtocolValue        = 1
  983. };
  984.  
  985. enum {
  986.     kHIDKeyboardInterfaceProtocol = 1,
  987.     kHIDMouseInterfaceProtocol    = 2
  988. };
  989.  
  990. enum {
  991.     kHIDSetLEDStateByBits        = 1,
  992.     kHIDSetLEDStateByBitMask    = 1,
  993.     kHIDSetLEDStateByIDNumber    = 2,
  994.     kHIDRemoveInterruptHandler    = 3,
  995.     kHIDEnableDemoMode            = 4,
  996.     kHIDDisableDemoMode            = 5,
  997.     kHIDRemoveNotification        = 0x1000
  998. };
  999.  
  1000. enum {
  1001.     kHIDGetLEDStateByBits        = 1,                            /* not supported in 1.0 of keyboard module*/
  1002.     kHIDGetLEDStateByBitMask    = 1,                            /* not supported in 1.0 of keyboard module*/
  1003.     kHIDGetLEDStateByIDNumber    = 2,
  1004.     kHIDGetDeviceCountryCode    = 3,                            /* not supported in 1.0 HID modules*/
  1005.     kHIDGetDeviceUnitsPerInch    = 4,                            /* only supported in mouse HID module*/
  1006.     kHIDGetInterruptHandler        = 5,
  1007.     kHIDGetCurrentKeys            = 6,                            /* only supported in keyboard HID module*/
  1008.     kHIDGetInterruptRefcon        = 7,
  1009.     kHIDGetVendorID                = 8,
  1010.     kHIDGetProductID            = 9
  1011. };
  1012.  
  1013.  
  1014. enum {
  1015.     kNumLockLED                    = 0,
  1016.     kCapsLockLED                = 1,
  1017.     kScrollLockLED                = 2,
  1018.     kComposeLED                    = 3,
  1019.     kKanaLED                    = 4
  1020. };
  1021.  
  1022. enum {
  1023.     kNumLockLEDMask                = 1 << kNumLockLED,
  1024.     kCapsLockLEDMask            = 1 << kCapsLockLED,
  1025.     kScrollLockLEDMask            = 1 << kScrollLockLED,
  1026.     kComposeLEDMask                = 1 << kComposeLED,
  1027.     kKanaLEDMask                = 1 << kKanaLED
  1028. };
  1029.  
  1030. enum {
  1031.     kUSBCapsLockKey                = 0x39,
  1032.     kUSBNumLockKey                = 0x53,
  1033.     kUSBScrollLockKey            = 0x47
  1034. };
  1035.  
  1036.  
  1037. struct USBMouseData {
  1038.     UInt16                             buttons;
  1039.     SInt16                             XDelta;
  1040.     SInt16                             YDelta;
  1041. };
  1042. typedef struct USBMouseData                USBMouseData;
  1043. typedef USBMouseData *                    USBMouseDataPtr;
  1044.  
  1045. struct USBKeyboardData {
  1046.     UInt16                             keycount;
  1047.     UInt16                             usbkeycode[32];
  1048. };
  1049. typedef struct USBKeyboardData            USBKeyboardData;
  1050. typedef USBKeyboardData *                USBKeyboardDataPtr;
  1051.  
  1052. union USBHIDData {
  1053.     USBKeyboardData                 kbd;
  1054.     USBMouseData                     mouse;
  1055. };
  1056. typedef union USBHIDData                USBHIDData;
  1057. typedef USBHIDData *                    USBHIDDataPtr;
  1058. EXTERN_API_C( void )
  1059. StartCompoundClassDriver        (USBDeviceRef             device,
  1060.                                  UInt16                 classID,
  1061.                                  UInt16                 subClass);
  1062.  
  1063. enum {
  1064.     kUSBCompositeClass            = 0,
  1065.     kUSBAudioClass                = 1,
  1066.     kUSBCommClass                = 2,
  1067.     kUSBHIDClass                = 3,
  1068.     kUSBDisplayClass            = 4,
  1069.     kUSBPrintingClass            = 7,
  1070.     kUSBMassStorageClass        = 8,
  1071.     kUSBHubClass                = 9,
  1072.     kUSBDataClass                = 10,
  1073.     kUSBVendorSpecificClass        = 0xFF
  1074. };
  1075.  
  1076. enum {
  1077.     kUSBCompositeSubClass        = 0,
  1078.     kUSBHubSubClass                = 1,
  1079.     kUSBPrinterSubclass            = 1,
  1080.     kUSBVendorSpecificSubClass    = 0xFF
  1081. };
  1082.  
  1083. enum {
  1084.     kUSBHIDInterfaceClass        = 0x03
  1085. };
  1086.  
  1087. enum {
  1088.     kUSBNoInterfaceSubClass        = 0x00,
  1089.     kUSBBootInterfaceSubClass    = 0x01
  1090. };
  1091.  
  1092. enum {
  1093.     kUSBNoInterfaceProtocol        = 0x00,
  1094.     kUSBKeyboardInterfaceProtocol = 0x01,
  1095.     kUSBMouseInterfaceProtocol    = 0x02,
  1096.     kUSBVendorSpecificProtocol    = 0xFF
  1097. };
  1098.  
  1099. enum {
  1100.     kUSBPrinterUnidirectionalProtocol = 0x01,
  1101.     kUSBPrinterBidirectionalProtocol = 0x02
  1102. };
  1103.  
  1104.  
  1105. enum {
  1106.     kServiceCategoryUSB            = FOUR_CHAR_CODE('usb ')        /* USB*/
  1107. };
  1108.  
  1109. /* SOMETHING NEEDS TO BE DONE WITH THIS - */
  1110. enum {
  1111.     kUSBTypeIsHub                = FOUR_CHAR_CODE('hubd'),        /* Hub*/
  1112.     kUSBTypeIsHID                = FOUR_CHAR_CODE('HIDd'),        /* Human Interface Device*/
  1113.     kUSBTypeIsDisplay            = FOUR_CHAR_CODE('disp'),        /* Display */
  1114.     kUSBTypeIsModem                = FOUR_CHAR_CODE('modm')        /* Modem*/
  1115. };
  1116.  
  1117. enum {
  1118.     kUSBDriverFileType            = FOUR_CHAR_CODE('ndrv'),
  1119.     kUSBDriverRsrcType            = FOUR_CHAR_CODE('usbd'),
  1120.     kUSBShimRsrcType            = FOUR_CHAR_CODE('usbs')
  1121. };
  1122.  
  1123. enum {
  1124.     kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
  1125. };
  1126.  
  1127. enum {
  1128.     kInitialUSBDriverDescriptor    = 0
  1129. };
  1130.  
  1131.  
  1132.  
  1133. typedef UInt32                             USBDriverDescVersion;
  1134. /*  Driver Loading Options*/
  1135. typedef UInt32                             USBDriverLoadingOptions;
  1136. enum {
  1137.     kUSBDoNotMatchGenericDevice    = 0x00000001,                    /* Driver's VendorID must match Device's VendorID*/
  1138.     kUSBDoNotMatchInterface        = 0x00000002,                    /* Do not load this driver as an interface driver.*/
  1139.     kUSBProtocolMustMatch        = 0x00000004,                    /* Do not load this driver if protocol field doesn't match.*/
  1140.     kUSBInterfaceMatchOnly        = 0x00000008                    /* Only load this driver as an interface driver.*/
  1141. };
  1142.  
  1143. enum {
  1144.     kClassDriverPluginVersion    = 0x00001100
  1145. };
  1146.  
  1147.  
  1148.  
  1149.  
  1150. struct USBDeviceInfo {
  1151.     UInt16                             usbVendorID;                /* USB Vendor ID*/
  1152.     UInt16                             usbProductID;                /* USB Product ID.*/
  1153.     UInt16                             usbDeviceReleaseNumber;        /* Release Number of Device*/
  1154.     UInt16                             usbDeviceProtocol;            /* Protocol Info.*/
  1155. };
  1156. typedef struct USBDeviceInfo            USBDeviceInfo;
  1157. typedef USBDeviceInfo *                    USBDeviceInfoPtr;
  1158.  
  1159. struct USBInterfaceInfo {
  1160.     UInt8                             usbConfigValue;                /* Configuration Value*/
  1161.     UInt8                             usbInterfaceNum;            /* Interface Number*/
  1162.     UInt8                             usbInterfaceClass;            /* Interface Class*/
  1163.     UInt8                             usbInterfaceSubClass;        /* Interface SubClass*/
  1164.     UInt8                             usbInterfaceProtocol;        /* Interface Protocol*/
  1165. };
  1166. typedef struct USBInterfaceInfo            USBInterfaceInfo;
  1167. typedef USBInterfaceInfo *                USBInterfaceInfoPtr;
  1168.  
  1169. struct USBDriverType {
  1170.     Str31                             nameInfoStr;                /* Driver's name when loading into the Name Registry.*/
  1171.     UInt8                             usbDriverClass;                /* USB Class this driver belongs to.*/
  1172.     UInt8                             usbDriverSubClass;            /* Module type*/
  1173.     NumVersion                         usbDriverVersion;            /* Class driver version number.*/
  1174. };
  1175. typedef struct USBDriverType            USBDriverType;
  1176. typedef USBDriverType *                    USBDriverTypePtr;
  1177.  
  1178. struct USBDriverDescription {
  1179.     OSType                             usbDriverDescSignature;        /* Signature field of this structure.*/
  1180.     USBDriverDescVersion             usbDriverDescVersion;        /* Version of this data structure.*/
  1181.     USBDeviceInfo                     usbDeviceInfo;                /* Product & Vendor Info*/
  1182.     USBInterfaceInfo                 usbInterfaceInfo;            /* Interface info*/
  1183.     USBDriverType                     usbDriverType;                /* Driver Info.*/
  1184.     USBDriverLoadingOptions         usbDriverLoadingOptions;    /* Options for class driver loading.*/
  1185. };
  1186. typedef struct USBDriverDescription        USBDriverDescription;
  1187. typedef USBDriverDescription *            USBDriverDescriptionPtr;
  1188. /*
  1189.    Dispatch Table
  1190.    Definition of class driver's HW Validation proc.
  1191. */
  1192. typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1193. /*
  1194.    Definition of class driver's device initialization proc.
  1195.    Called if the driver is being loaded for a device
  1196. */
  1197. typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  1198. /* Definition of class driver's interface initialization proc.*/
  1199. typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
  1200. /* Definition of class driver's finalization proc.*/
  1201. typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1202.  
  1203. typedef UInt32                             USBDriverNotification;
  1204. enum {
  1205.     kNotifySystemSleepRequest    = 0x00000001,
  1206.     kNotifySystemSleepDemand    = 0x00000002,
  1207.     kNotifySystemSleepWakeUp    = 0x00000003,
  1208.     kNotifySystemSleepRevoke    = 0x00000004,
  1209.     kNotifyHubEnumQuery            = 0x00000006,
  1210.     kNotifyChildMessage            = 0x00000007,
  1211.     kNotifyExpertTerminating    = 0x00000008,
  1212.     kNotifyDriverBeingRemoved    = 0x0000000B,
  1213.     kNotifyAllowROMDriverRemoval = 0x0000000E
  1214. };
  1215.  
  1216. /*
  1217.    Definition of driver's notificatipn proc.      
  1218.    Added refcon for 1.1 version of dispatch table
  1219. */
  1220. typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
  1221.  
  1222. struct USBClassDriverPluginDispatchTable {
  1223.     UInt32                             pluginVersion;
  1224.     USBDValidateHWProcPtr             validateHWProc;                /* Proc for driver to verify proper HW*/
  1225.     USBDInitializeDeviceProcPtr     initializeDeviceProc;        /* Proc that initializes the class driver.*/
  1226.     USBDInitializeInterfaceProcPtr     initializeInterfaceProc;    /* Proc that initializes a particular interface in the class driver.*/
  1227.     USBDFinalizeProcPtr             finalizeProc;                /* Proc that finalizes the class driver.*/
  1228.     USBDDriverNotifyProcPtr         notificationProc;            /* Proc to pass notifications to the driver.*/
  1229. };
  1230. typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
  1231. typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
  1232. /* Hub defines*/
  1233.  
  1234.  
  1235. enum {
  1236.     kUSBHubDescriptorType        = 0x29
  1237. };
  1238.  
  1239. enum {
  1240.                                                                 /* Hub features */
  1241.     kUSBHubLocalPowerChangeFeature = 0,
  1242.     kUSBHubOverCurrentChangeFeature = 1,                        /* port features */
  1243.     kUSBHubPortConnectionFeature = 0,
  1244.     kUSBHubPortEnableFeature    = 1,
  1245.     kUSBHubPortSuspendFeature    = 2,
  1246.     kUSBHubPortOverCurrentFeature = 3,
  1247.     kUSBHubPortResetFeature        = 4,
  1248.     kUSBHubPortPowerFeature        = 8,
  1249.     kUSBHubPortLowSpeedFeature    = 9,
  1250.     kUSBHubPortConnectionChangeFeature = 16,
  1251.     kUSBHubPortEnableChangeFeature = 17,
  1252.     kUSBHubPortSuspendChangeFeature = 18,
  1253.     kUSBHubPortOverCurrentChangeFeature = 19,
  1254.     kUSBHubPortResetChangeFeature = 20
  1255. };
  1256.  
  1257.  
  1258. enum {
  1259.     kHubPortConnection            = 1,
  1260.     kHubPortEnabled                = 2,
  1261.     kHubPortSuspend                = 4,
  1262.     kHubPortOverCurrent            = 8,
  1263.     kHubPortBeingReset            = 16,
  1264.     kHubPortPower                = 0x0100,
  1265.     kHubPortSpeed                = 0x0200
  1266. };
  1267.  
  1268. enum {
  1269.     kHubLocalPowerStatus        = 1,
  1270.     kHubOverCurrentIndicator    = 2,
  1271.     kHubLocalPowerStatusChange    = 1,
  1272.     kHubOverCurrentIndicatorChange = 2
  1273. };
  1274.  
  1275. enum {
  1276.     off                            = false,
  1277.     on                            = true
  1278. };
  1279.  
  1280.  
  1281.  
  1282. struct hubDescriptor {
  1283.                                                                 /* See usbDoc pg 250?? */
  1284.     UInt8                             dummy;                        /* to align charcteristics */
  1285.  
  1286.     UInt8                             length;
  1287.     UInt8                             hubType;
  1288.     UInt8                             numPorts;
  1289.  
  1290.     UInt16                             characteristics;
  1291.     UInt8                             powerOnToGood;                /* Port settling time, in 2ms */
  1292.     UInt8                             hubCurrent;
  1293.  
  1294.                                                                 /* These are received packed, will have to be unpacked */
  1295.     UInt8                             removablePortFlags[8];
  1296.     UInt8                             pwrCtlPortFlags[8];
  1297. };
  1298. typedef struct hubDescriptor            hubDescriptor;
  1299.  
  1300.  
  1301.  
  1302. #if PRAGMA_STRUCT_ALIGN
  1303.     #pragma options align=reset
  1304. #elif PRAGMA_STRUCT_PACKPUSH
  1305.     #pragma pack(pop)
  1306. #elif PRAGMA_STRUCT_PACK
  1307.     #pragma pack()
  1308. #endif
  1309.  
  1310. #ifdef PRAGMA_IMPORT_OFF
  1311. #pragma import off
  1312. #elif PRAGMA_IMPORT
  1313. #pragma import reset
  1314. #endif
  1315.  
  1316. #ifdef __cplusplus
  1317. }
  1318. #endif
  1319.  
  1320. #endif /* __USB__ */
  1321.  
  1322.